package com.xf.auth.service.impl.member;

import com.xf.common.core.enums.YesOrNoEnum;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.HashSet;


/**
 * 用户认证信息
 *
 */
@Data
public class MemberUserDetails implements UserDetails {

    private String userCode;
    private String username;
    private String telPhone;
    private Boolean enabled;

    /**
     * 认证方式
     */
    private String authenticationMethod;


    /**
     * 小程序用户体系
     *
     * @param member 小程序用户认证信息
     */
    public MemberUserDetails(MemberAuthDTO member) {
        this.setUserCode(member.getUserCode());
        this.setUsername(member.getUsername());
        this.setTelPhone(member.getTelPhone());
        this.setEnabled(YesOrNoEnum.Yes.getValue().intValue() == member.getStatus());
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return new HashSet<>();
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }
}
